package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/28 10:56
 **/
public class Day43_3_Num6161_RemoveStars {
    public static String removeStars(StringBuffer s) {
        StringBuffer sb = new StringBuffer(s);
        for(int i = 0; i < sb.length(); ++i){
            if(sb.charAt(i) == '*'){
                if(i + 1 < sb.length()){
                    sb = sb.append(sb.substring(0, i-1)).append(sb.substring(i+1, s.length()));
                }else {
                    sb = sb.append(sb.substring(0, i-1));
                }
                i = i-2;
                sb = new StringBuffer(s);
            }
        }
        return sb.toString();
    }
    class Solution {
        public String removeStars(String s) {
            StringBuffer sb = new StringBuffer(s);
            for(int i = 0; i < s.length(); ++i){
                if(sb.charAt(i) == '*'){
                    sb.deleteCharAt(sb.length()-1);
                }else {
                    sb.append(s.charAt(i));
                }
            }
            return sb.substring(s.length(),sb.length()).toString();
        }
    }
}